package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.baidu.mapapi.map.Text;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.CRMBaseBean;
import com.lzx.iteam.bean.CRMLibraryListData;
import com.lzx.iteam.bean.ScheduleManager;
import com.lzx.iteam.util.ImageLoaderInterface;
import com.lzx.iteam.widget.RoundImageView;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 08月 11日
 * Time: 下午3:18
 *
 * @QQ : 1234567890
 * **********************************
 */
public class SelectContactAdapter extends BaseAdapter{

    private Context mContext;
    private int mType;
    private ArrayList<CRMLibraryListData> mListData = new ArrayList<CRMLibraryListData>();
    private LayoutInflater mInflater;

    public SelectContactAdapter(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    public void bindData(int type,ArrayList<CRMLibraryListData> data){
        this.mType = type;
        this.mListData = data;
    }

    @Override
    public int getCount() {
        return mListData.size();
    }

    @Override
    public Object getItem(int position) {
        return mListData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CRMLibraryListData data = mListData.get(position);
        ViewHolder holder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.list_item_layout,null);
            holder = new ViewHolder();
            holder.avatar = (RoundImageView) convertView.findViewById(R.id.iv_item_avatar);
            holder.title = (TextView) convertView.findViewById(R.id.item_tv_title);
            holder.content = (TextView) convertView.findViewById(R.id.item_tv_content);
            holder.image = (ImageView) convertView.findViewById(R.id.iv_item_right);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if (mType == 1){
            holder.avatar.setVisibility(View.GONE);
            holder.image.setVisibility(View.VISIBLE);
        }else if (mType == 2){
            holder.avatar.setVisibility(View.VISIBLE);
            holder.image.setVisibility(View.GONE);
//            ImageLoaderInterface.imageLoader.displayImage(data.getImage(),holder.avatar,ImageLoaderInterface.optionHeadImage);
        }
        holder.title.setText(data.getName());
        holder.content.setText(data.getPhone());
        return convertView;
    }

    class ViewHolder{
        RoundImageView avatar;
        TextView title,content;
        ImageView image;
    }

}
